<?php
/*
 * Created on 08.01.2007
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 * 
 * <example:bodyProcess></example:bodyProcess>
 */

m2import('phpinchains/psp/MethodTag.php');

class cms_includedocHandler extends phpinchains_psp_MethodTag
{

    /**
     * Is a body tag (if false, body is ignored)
     */
    var $tagType = PSP_EMPTY_TAG;
    /**
     * Tag name in form namespace:tagname
     */
    var $tagName   = 'cms:includedoc';

    var $requiredAttributes = array(
        'src' => '(pageid:\d+|\d+)', // pageid:<id> or <id>
        'tpl' => '.*'

    );
    var $attributes = array(
            'jumpLink' // show jump Link to Inc Doc Editor
    );
    
    function doStartTag()
    {
        // initializes $this->buffer and pushes the listener on the stack of the 
        // main output writer
        preg_match('/pageid:(\d+)/', $this->getAttribute('src'), $matches);
        $doc_id = (int) $matches[1];
        if (!$doc_id)
            $doc_id = (int) $this->getAttribute ('src');
        $ctx = base_ApplicationContext::getInstance();
        if ($ctx->getDocumentContext()->getRoot()->getBuildMode() == base_templateEngine_BuildModes::$EDITOR && ($this->getAttribute('jumpLink')=='true' || $this->getAttribute('jumpLink') === true)) {
            $this->out->write('<div class="xicstitle">Include-Doc: <a title="Zum Dokument-Editor" href="javascript:top.showDoc(' . $doc_id . ')"><img src="' . $ctx->mediaPath()->main() . '/cms/pencil_go.png"/></a></div>');
        }
        $dctx = $ctx->getDocumentContext()->createChildDocumentContext($doc_id, '../inc/'.$this->getAttribute('tpl'));
        $te = new base_templateEngine_TemplateEngine($dctx, null); // ",null" hinzugefügt von LJ 2011 07 19
        $this->out->write($te->process());
        $dba = $ctx->getAccessFactory()->getInstanceOf(base_AccessFactory::$CMS);
        $this->related_docs[] = $doc_id;
        $this->registerRelatedDocuments($dctx);
        unset($dctx);
        unset($te);
        return PSP_SKIP_BODY;
    }

    function doEndTag()
    {
        return PSP_SKIP_BODY;
    }

}
?>